<template>
	<view class="container">
		<view class="example">
			<uni-forms ref="form" :model="user" labelWidth="80px">
				<uni-forms-item label="登录账号">
					<uni-easyinput v-model="user.username" disabled="" placeholder="请输入昵称" />
				</uni-forms-item>
				<uni-forms-item label="中文名称">
					<uni-easyinput v-model="user.chineseName" placeholder="请输入昵称" />
				</uni-forms-item>
				<uni-forms-item label="英文名称(默认)">
					<uni-easyinput v-model="user.realName" placeholder="请输入昵称" />
				</uni-forms-item>
				<uni-forms-item label="手机号码" name="mobile">
					<uni-easyinput v-model="user.mobile" placeholder="请输入手机号码" />
				</uni-forms-item>
				<uni-forms-item label="邮箱" name="email">
					<uni-easyinput v-model="user.email" placeholder="请输入邮箱" />
				</uni-forms-item>

			</uni-forms>
			<button class="  block bg-black  noR" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {
		getUserProfile
	} from "@/api/system/user"
	import {
		updateUserProfile
	} from "@/api/system/user"
	import {
		doUpdate
	} from '../../../api/system/user/userManagement'

	export default {
		data() {
			return {
				user: {
					avatar: "",
					username: "",

					chineseName: "",
					realName: "",
					mobile: "",
					email: "",
					sex: ""
				},
				sexs: [{
					text: '男',
					value: "0"
				}, {
					text: '女',
					value: "1"
				}],
				rules: {
					chineseName: {
						rules: [{
							required: true,
							errorMessage: '中文昵称不能为空'
						}]
					},
					realName: {
						rules: [{
							required: true,
							errorMessage: '英文昵称不能为空'
						}]
					},
					mobile: {
						rules: [{
							required: true,
							errorMessage: '手机号码不能为空'
						}, {
							pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
							errorMessage: '请输入正确的手机号码'
						}]
					},
					email: {
						rules: [{
							required: true,
							errorMessage: '邮箱地址不能为空'
						}, {
							format: 'email',
							errorMessage: '请输入正确的邮箱地址'
						}]
					}
				}
			}
		},
		onLoad() {
			this.getUser()
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			getUser() {
				this.user = this.$store.state.user.user
			},
			async update() {
				await doUpdate(this.user)
				this.$modal.msgSuccess("修改成功")
			},
			submit(ref) {
				this.$refs.form.validate().then(res => {
					this.update()
					this.$modal.msgSuccess("修改成功")
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style>